﻿using BusinessLayer;
using BusinessLayer.VDataEntities;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using TrialManagementTool.App_Start;
using TrialManagementTool.Helper;
using TrialManagementTool.Models;

namespace TrialManagementTool.Controllers.API
{
    [WebApiExceptionFilter]
    [APIAuthorize]
    public class ProductController : ApiController
    {
        public VProduct[] GetAllProducts()
        {
            VRichProduct[] products = BusinessLayer.ProductBusiness.GetAllProductListWithoutOthers();
            return products;
        }

        public void UpdateProductStatus(VProduct Product)
        {
            BusinessLayer.ProductBusiness.ChangeStatus(Product.ID);
        }

        public void AddProduct(ProductModel Product)
        {
            BusinessLayer.ProductBusiness.AddProduct(Product.name,Product.categoryId);
        }

        public VDataEntity[] GetProductCategoryList()
        {
            List<VDataEntity> result = ProductBusiness.GetProductCategoryList();
            result.Insert(0, new VDataEntity { ID = 0, Name = "请选择" });
            return result.ToArray();
            // return ProductBusiness.GetProductCategoryList();
        }

        public List<VDataEntity> GetActiveProductListByProductCategory(long id)
        {
            List<VDataEntity> result = new List<VDataEntity>();
            result.Insert(0, new VDataEntity { ID = 0, Name = "请选择" });
            result.AddRange(ProductBusiness.GetActiveProductListByProductCategory(id).ToList());
            return result;
        }
    }
}
